#include "channel.h"
#include<functional>
#include<memory>
#include<iostream>

Channel::Channel(std::shared_ptr<Epoll> _ep, int _fd, uint32_t _events, std::function<void()> _cb): 
ep(_ep), fd(_fd), events(_events), inEpoll(false), cb(_cb) {
}

Channel::Channel(int _fd, uint32_t _events, std::function<void()> _cb): 
fd(_fd), events(_events), inEpoll(false), cb(_cb) {
}

Channel::~Channel()
{
}

void Channel::enableReading(){
    events = EPOLLIN | EPOLLET;
    ep->updateChannel(this);
}

int Channel::getFd(){
    return fd;
}

uint32_t Channel::getEvents(){
    return events;
}

bool Channel::getInEpoll(){
    return inEpoll;
}

void Channel::setInEpoll(){
    inEpoll = true;
}

void Channel::handleEvent(){
    cb();
}

// void Channel::setCallback(std::function<void()> _cb){
//     cb = _cb;
// }